2024-04-29

The basics

Rendering R Markdown documents

R Markdown makes it easy to turn a document of notes into different output formats including presentations.

For example …

… I might start to collect some notes on “Presentations with R Markdown” in a simple R Markdown document.

I want to include some references and start with a simple document with the following YAML header:

Controlling output with YAML

---
title: "Presentations with R Markdown"
subtitle: "Some examples"
author: Stefan Daume
date: "2024-04-29"
output: 
  bookdown::html_document2:
    theme: paper
always_allow_html: true
bibliography: references.bib
link-citations: no
---

Using knitr (e.g. the “Knit” button in RStudio) renders this document as an HTML page.

R Markdown as an HTML page

Which would look like that:

R Markdown

As with any R Markdown document embedded R code chunks will be evaluated and included in the rendered document. For example:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

Or a plot:

plot(pressure)

R Markdown book

Consult the R Markdown book (Xie, Allaire, and Grolemund 2023) for more options.

Including this citation demonstrates how dynamic references and bibliographies can be included in any R Markdown output format. Check the “References” section at the end of the document.

Move to presentation format

Change the output format

By changing the output format in the YAML header we can turn the initial document into a presentation.

---
title: "Presentations with R Markdown"
subtitle: "Some examples"
author: Stefan Daume
date: "2024-04-29"
output:
  ioslides_presentation:
    widescreen: true
always_allow_html: true
bibliography: references.bib
link-citations: no
---

ioslides is only one of several supported HTML presentation formats.

Structuring the presentation

In most supported HTML presentation formats slides headers of type # and ## are translated in individual slides with the header text as slide title.

Using --- creates a slide without a title.

Useful features

Online presentations

Document conversion with pandoc

A more involved approach

The ‘heavy lifting’ of document transformations from R Markdown is enabled with pandoc (https://pandoc.org/).

Using pandoc may offer useful additional options when converting documents.

An alternative approach to creating presentations from R Markdown and using pandoc directly is documented here: https://github.com/sdaume/rmarkdown-presentation-template (slightly outdated now)

R Markdown, pandoc, reveal.js

The referenced example creates a HTML presentation based on the reveal.js framework, starting with R Markdown it uses pandoc to create presentations like this.

It is versatile, offers different plugins and makes it possible to include advanced visualizations such as this

References

Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2023. R Markdown: The Definitive Guide.